package com.study.zzedu.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aliyun.player.alivcplayerexpand.bean.LongVideoBean;
import com.study.zzedu.R;
import com.study.zzedu.entity.QualityLessonItem;
import com.study.zzedu.ui.study.StudyActivity;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 *
 */

public class QualityLessonAdapter extends RecyclerView.Adapter {

    private Context context;
    private List data;

    private final static int HEAD_COUNT = 1;

    private LongVideoBean bean = new LongVideoBean();
    private final static int TYPE_HEAD = 0;
    private final static int TYPE_CONTENT = 1;
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd

    @Override
    public int getItemViewType(int position) {
        return TYPE_CONTENT;
    }

    public QualityLessonAdapter(Context context, List data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.layout_online_lesson_item, parent, false);
        return new ContentHolder(itemView);

    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentHolder) { // 内容
            final QualityLessonItem item = (QualityLessonItem) data.get(position);

            ContentHolder myHolder = (ContentHolder) holder;
            myHolder.lessonName.setText(item.getCourseName());
//            myHolder.status.setText(item.getStatus());
//            myHolder.tv_begintime.setText(item.getBeginDate() + "直播");

            myHolder.status.setVisibility(View.GONE);
            myHolder.tv_go_view.setVisibility(View.GONE);
            myHolder.tv_review.setVisibility(View.GONE);
            myHolder.ll_item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, StudyActivity.class);
                    intent.putExtra("courseCode", item.getCourseCode());
                    //intent.putExtra("chapterCode", item.get());
                    intent.putExtra("lessonName", item.getCourseName());
                    intent.putExtra("score", "");
                    intent.putExtra("examType", "");
                    intent.putExtra("totalHour", item.getTotalHour());
                    intent.putExtra("from","quality");
                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    //内容
    public class ContentHolder extends RecyclerView.ViewHolder {

        private LinearLayout ll_item;
        private TextView lessonName, tv_curTerm, tv_go_view, tv_review, tv_begintime;
        private ImageView imgUrl;
        private TextView status;

        public ContentHolder(View itemView) {
            super(itemView);
            ll_item = itemView.findViewById(R.id.ll_item);
            lessonName = itemView.findViewById(R.id.lesson_name);
            imgUrl = itemView.findViewById(R.id.lesson_img);
            status = itemView.findViewById(R.id.tv_status);

            tv_curTerm = itemView.findViewById(R.id.tv_curTerm);
            tv_go_view = itemView.findViewById(R.id.tv_go_view);
            tv_review = itemView.findViewById(R.id.tv_review);
            tv_begintime = itemView.findViewById(R.id.tv_begintime);
        }
    }
}
